package com.rqbl.controller;


import com.rqbl.entity.Interest;
import com.rqbl.entity.User;
import com.rqbl.mapper.UserinterestMapper;
import com.rqbl.myutils.BarInterestJSON;
import com.rqbl.myutils.Transfer;
import com.rqbl.service.UserinterestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bruce
 * @since 2024-07-19
 */
@RestController
@RequestMapping("/userinterest")
public class UserinterestController {
    @Autowired
    private UserinterestService userinterestService;

    @RequestMapping("getInterestByuid")
    @ResponseBody
    public List<Transfer> getInterestByuid(HttpSession session){
        User user = (User) session.getAttribute("user");
        return userinterestService.getInterestByuid(user.getUid());
    }

    @RequestMapping("updateInterestByuid")
    @ResponseBody
    public String updateInterestByuid(@RequestBody  BarInterestJSON barInterestJSON,HttpSession session){
        User user = (User) session.getAttribute("user");
        System.out.println("transfer"+barInterestJSON.getTransfers());
        return userinterestService.updateInterestByuid(barInterestJSON.getTransfers(),user.getUid())>0 ? "success" : "fail";
    }

}
